<template>
	<view class="content" v-if="!isccccc">
		<u-navbar title="提问" :is-back="false" :color="titleColor"></u-navbar>
		<view style="padding: 0 32rpx;margin-top: 48rpx;">
			<textarea placeholder-style="color:#B7B7B7;font-size: 32rpx;"
				style="height:270rpx;width: 100%;font-size: 32rpx;border-bottom: 1px solid #DBDDE0;"
				placeholder="请在此输入您的提问内容，200字以内" maxlength="200" v-model="wenti" @input="inwenti" />
		</view>
		<view class="cu-list menu  sm-border">
			<view class="cu-item ">
				<view class="content" @click="showHangyeList" style="position: relative;">
					<image src="../../../static/img/ic-quiz-industry.png" mode="widthFix"
						style="width: 40rpx;margin-right: 10rpx;"></image>
					<!-- <text class="cuIcon-circlefill text-grey"></text> -->
					<text class=" item-text">所属行业</text>
					<view style="position: absolute;right: 10rpx;top: 0;font-size: 24rpx;display: flex;"
						:style="[{'color':selhangye?'#3f48cc':''}]">
						<view style="margin-right: 20rpx;">{{selhangye?selhangye.industryName:'未选择'}}</view>
						<u-icon name="arrow-right"></u-icon>
					</view>

				</view>
			</view>
			<!-- 			<view class="cu-item arrow">
				<view class="content"  style="position: relative;" @click="seljine()">
					<image src="../../../static/img/ic-quiz-offer.png" mode="widthFix"
						style="width: 40rpx;margin-right: 10rpx;"></image>
					<text class=" item-text">悬赏问答</text>
					<view style="position: absolute;right: 0rpx;top: 0;font-size: 24rpx;" :style="[{'color':jine>0?'#EB8252':''}]">
						{{jine?jine>0:'未设置'}}</view>
				</view>
			</view> -->
			<view class="cu-item ">
				<view class="content" style="position: relative;">
					<!-- <text class="cuIcon-circlefill text-grey"></text> -->
					<image src="../../../static/img/teach-icon.png" mode="widthFix"
						style="width: 40rpx;margin-right: 10rpx;"  @click.stop="selTeacherfun()"></image>
					<text class=" item-text"  @click.stop="selTeacherfun()">指定老师</text>
					<view style="position: absolute;right: 10rpx;top: 0;font-size: 24rpx;display: flex;"
						:style="[{'color':selTeacher?'#3f48cc':''}]">
						<view style="margin-right: 20rpx;"  @click.stop="selTeacherfun()">{{selTeacher?selTeacher.nickName:'未设置'}}</view>
						<u-icon name="arrow-right" v-if="!selTeacher"  @click.stop="selTeacherfun()"></u-icon>
						<u-icon name="close" v-if="selTeacher" @click.stop="clearteacher()"></u-icon>
					</view>

				</view>
			</view>
			<view @click="send()" class="fabu">发布</view>
		</view>
		<u-popup v-model="hangyeshow" mode="bottom" border-radius="14">
			<view style="width: 100%;text-align: center;font-weight: bolder;padding: 20rpx 0;font-size: 28rpx;">选择问题行业</view>
			<view style="max-height: 600rpx;overflow-y: scroll;padding: 20rpx;" class="grid col-3">
				<view v-for="item in liIndustryList" style="text-align: center;font-size: 24rpx;">
					<view style="padding: 20rpx;" @click="selectHY(item)">
						<image :src="item.industryIcon" mode="widthFix"
							style="width: 60rpx;display: block;margin: 0 auto;"></image>
						<view style="margin-top: 10rpx;">{{item.industryName}}</view>
					</view>
				</view>
			</view>
		</u-popup>
		<u-popup v-model="showList" mode="bottom" border-radius="14">
			<view style="width: 100%;text-align: center;font-weight: bolder;padding: 20rpx 0;font-size: 28rpx;">选择提问老师</view>
			<scroll-view style="height: 700rpx;padding: 20rpx;width: 100%;" scroll-y class="grid col-3">
				<indexes v-if="showList" style="width: 100%;" @selitem="selitem"></indexes>
			</scroll-view>
		</u-popup>
	</view>
</template>

<script>
	import {
		http,
		Method
	} from "@/utils/request.js";
	import storage from "@/utils/storage.js";
	import indexes from "./indexes.vue"
	export default {
		data() {
			return {
				selTeacher: null,
				jine: 0,
				selhangye: null,
				hangyeshow: false,
				wenti: "",
				liIndustryList: [],
				showList:false,
				isccccc:true,
			}
		},
		components: {
			indexes
		},
		async mounted() {
			 this.isccccc = uni.getStorageSync("isccccc");
		},
		methods: {
			clearteacher(){
				this.selTeacher=null;
			},
			selitem(item){
				this.showList=false;
				console.log("******selitem******",item)
				this.selTeacher={...item}
			},
			inwenti(e) {
				this.wenti = e.detail.value
			},
			async getUserProfile(e) {
				// 开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
				let data = await uni.getUserProfile({
					desc: '用于显示用户昵称', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
				});
				let userInfo = data[1];
				return userInfo;
			},
			async send() {
				let that = this;
				if (this.$options.filters.isLogin("auth")) {

				} else {
					uni.showModal({
						title: "提示",
						content: "检测到您的账号还未登录,是否去登录？",
						confirmColor: this.$lightColor,
						success: function(res) {
							if (res.confirm) {
								that.$options.filters.navigateToLogin();
							} else if (res.cancel) {
								uni.navigateBack();
							}
						},
					});
					return;
				}
				let wenti = this.wenti;
				let selhangye = this.selhangye;
				let user = storage.getUserInfo();
				if (!wenti) {
					uni.showToast({
						title: "请输入问题",
						icon: "error"
					})
				}
				if (!selhangye) {
					uni.showToast({
						title: "请输入选择行业",
						icon: "error"
					})
				}
				if (!user.face) {
					let userInfo = await this.getUserProfile()
					if (!userInfo.userInfo) {
						uni.showToast({
							title: "请授权昵称",
							icon: 'error'
						})
						return;
					}
					user["face"] = userInfo.userInfo.avatarUrl;
					user["nickName"] = userInfo.userInfo.nickName;
					storage.setUserInfo(storage)
				}
				let params = {
					title: "",
					content: this.wenti,
					createUserName: user["nickName"],
					createUserHread: user["face"],
					industryId: selhangye.id,
					userId: user.id,
					appointUser:this.selTeacher?this.selTeacher.id:""
				}
				uni.removeStorageSync("addjifen")
				uni.showLoading({
					mask: true,
					title: "发布中"
				})
				let res = await http.request({
					url: "/lili/liQuestions",
					method: Method.POST,
					needToken: true,
					params,
				});
				uni.hideLoading();
				let data = res.data || {};
				if (data.success) {
					uni.showToast({
						icon: "success",
						title: "发布成功"
					})
					this.wenti = "";
					this.selTeacher=null;
					this.selhangye = null;
					uni.navigateTo({
						url: "/pages/mine/my-questions"
					})
				}

			},
			selTeacherfun() {
				// uni.showToast({
				// 	title: "即将开放",
				// 	icon: "none"
				// });
				this.showList=true;
			},
			seljine() {
				uni.showToast({
					title: "即将开放",
					icon: "none"
				});
			},
			selectHY(item) {
				this.selhangye = {
					...item
				};
				this.hangyeshow = false;
			},
			async showHangyeList() {
				let params = {
					pageNumber: 1,
					pageSize: 999,
					sort: "create_time",
					order: "desc",
					isAdmin: false,
				}
				let res = await http.request({
					url: "/goods/goods/getLiIndustrys",
					method: Method.GET,
					needToken: true,
					params,
				});
				let data = res.data.result.records || [];
				data = data.filter(item => {
					return !item.deleteFlag
				})
				console.log("showHangyeList", res)
				this.liIndustryList = [...data]
				this.hangyeshow = true;
			},
		}
	}
</script>

<style>
	.item-text {
		font-size: 32rpx;
		font-family: HarmonyOS Sans SC;
		font-weight: bolder;
		color: #333333;
	}

	.fabu {
		margin: 0 auto;
		text-align: center;
		width: 150rpx;
		height: 150rpx;
		line-height: 150rpx;
		font-size: 32rpx;
		/* background: linear-gradient(44deg, #FF9565, #FF7133); */
		background: linear-gradient(44deg, #183c8d, #3c1264);
		box-shadow: 0rpx 1rpx 11rpx 1rpx rgba(0, 0, 0, 0.2800);
		border-radius: 50%;
		position: fixed;
		bottom: 140rpx;
		left: 0;
		right: 0;
		color: #fff;
	}
</style>
